package io.esirong.image.media;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;

/**
 * @ClassName: MediaActivity
 * @Description: 处理多媒体文件获取交互界面UI
 * @author: huangrongcai
 * @date: 2022/9/4
 */
public class MediaActivity extends Activity {
    public static String ARGS_TITLE = "title";
    public static String ARGS_CROP = "crop";
    public static String ARGS_SCALE = "scale";
    public static String ARGS_OUTPUTX = "outputX";
    public static String ARGS_OUTPUTY = "outputY";
    public static String ARGS_TYPE = "type";
    private static MediaResultListener sMediaResultListener;

    public static void setMediaResultListener(MediaResultListener listener) {
        MediaActivity.sMediaResultListener = listener;
    }

    public static void removeMediaResultListener() {
        sMediaResultListener = null;
    }
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        Media.TYPE type = intent.getParcelableExtra(ARGS_TYPE);
        String title = intent.getStringExtra(ARGS_TITLE);
        boolean crop = intent.getBooleanExtra(ARGS_CROP, false);
        boolean scale = intent.getBooleanExtra(ARGS_SCALE, false);
        int outputX = intent.getIntExtra(ARGS_OUTPUTX, -1);
        int outputY = intent.getIntExtra(ARGS_OUTPUTY, -1);

        if (type == Media.TYPE.IMAGE) {
            showImageSelectorUI();
        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        handleResult(requestCode, resultCode, data);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        MediaActivity.sMediaResultListener = null;
    }

    private void showImageSelectorUI() {

    }

    private void handleResult(int requestCode, int resultCode, Intent data) {

        if (sMediaResultListener != null) {
            sMediaResultListener.onResult(requestCode, resultCode, data);
        }
        removeMediaResultListener();
    }

}
